<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>大西信息科技有限公司</title>
	<link rel="icon" href="../static/img/favicon.ico" type="image/x-icon" >
    <link rel="stylesheet" href="static/css/qrcode.css">
    <link rel="stylesheet" href="static/css/common.css">
	
</head>
<body>
	<div class="header">
		<div class="ie">
			<img src="static/img/logo @2x.png" alt="">
			<p>中铁十二局集团第一工程有限公司</p>
		</div>
	</div>
    <form action="" method="post" class="login">
        <p class="name">登   录</p>
        <p class="loginType">
            <a href="login.html" id="psd"><span>密码登录</span></a>
            <a href="messageLogin.html" id="mes"><span>短信登录</span></a>
            <a href="qrcode.html" id="sao"><span>扫码登录</span></a>
        </p>
        <p class="code">
            <img src="" alt="" id="qrcode">
        </p>
        <p class="scan">
            请使用“数字土木APP”扫码登陆
        </p>
    </form>
    <div class="footer">
        <p class="dx">
			<a href="https://www.daxiit.com" target="_blank">西安大西信息科技有限公司 ©2019 </a>
			<a href="http://www.beian.miit.gov.cn" target="_blank" style="margin-left:10px;">陕ICP备15006746号</a>
		</p>
    </div>
	
</body>
</html>
<script src="../static/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/dx.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/js/input.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	$(document).ready(function(){
		// 获取uuid
		DX.ajax_method({
			'type':'GET',
			'url':'/user/login/getUUID',
			'param':{},
			'callBack':callBack
		});
		// 回调函数
		function callBack(res){
			// console.log(res);
			var uuid = res.data;
			var url = DX.domain('user')+'/user/login/getQRCodeImage?uuid='+uuid+'&r='+Math.random();
			// console.log(url);
			$('#qrcode').attr('src',url);
			monitor(uuid);
		}
		// 监听登录成功
		function monitor(uuid){
			var time = setInterval(function(){
				DX.ajax_method({
					'type':'POST',
					'url':'/user/login/isScanned',
					'param':{'uuid':uuid},
					'callBack':function(res){
						// console.log(res);
						if(res.code == '200'){
							clearInterval(time);
							DX.setCookie('token',res.data.Token);
							if(res.data.unitOrProject == "unit"){
								window.location.href='../office.html';
							}else{
								window.location.href='../index.html';	
							}
						}else if(res.code == '401'){
							clearInterval(time);
						}
						
					}
				})
			},1000)
		}
		$('#qrcode').click(function(){
			DX.ajax_method({
				'type':'GET',
				'url':'/user/login/getUUID',
				'param':{},
				'callBack':callBack
			});
		})
	})
</script>